﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NGourd.Core.Runners;
using NGourd.Core.Reports;
using NGourd.Core.Exceptions;

namespace NGourd.Core.Plans
{
    class ExecutePlanStep : IPlan
    {
        private readonly string text;
        private readonly ExecutableStep step;

        public ExecutePlanStep(ExecutableStep step, string text)
        {
            this.step = step;
            this.text = text;
        }

        #region IPlan Members

        public ReportNode Execute(bool skipExection)
        {
            if (skipExection)
            {
                return new ReportNode(ReportTarget.STEP, text) { Status = ReportStatus.SKIPPED };
            }
            try
            {
                step.Execute(text);
                return new ReportNode(ReportTarget.STEP, text) { Status = ReportStatus.PASSED };
            }
            catch (Exception ex)
            {
                return new ReportNode(ReportTarget.STEP, text + Environment.NewLine + ex.ToString()) { Status = ReportStatus.FAILED };
            }
        }

        #endregion
    }
}
